export function removeVaAPI(url) {
    // 将 /api/order/:id 转为 /^\/api\/order\/[^/]+$/
    const regStr = '^' + url.replace(/:\w+/g, '[^/]+') + '$';
    return new RegExp(regStr);
}

export function getOrInit(key, defaultValue) {
    let data = localStorage.getItem(key);
    if (data) {
        try {
            return JSON.parse(data);
        } catch {
            localStorage.setItem(key, JSON.stringify(defaultValue));
            return defaultValue;
        }
    } else {
        localStorage.setItem(key, JSON.stringify(defaultValue));
        return defaultValue;
    }
}
export function setToLS(key, value) {
    localStorage.setItem(key, JSON.stringify(value));
}